<template>
  <div class="page">
    <n-button type="primary" @click="backTop">backTopOrLeft</n-button>
    <div class="scroll_container">
      <!-- 纵向滚动 -->
      <!-- <BasiScrollcLIst ref="scrollRef" @touch-bottom-or-right="touch" class="y_scroll">
      <template #content>
        <div class="item2" v-for="item in data" :key="item">{{ item }}</div>
      </template>
    </BasiScrollcLIst> -->

      <div class="split"></div>

      <!-- 横向滚动 -->
      <BasiScrollcLIst
        ref="scrollRef"
        id="x_scroll"
        direction="x"
        :current-num="data"
        :total="30"
        @scrolling="scrolling"
        @touch-bottom-or-right="touch"
        class="x_scroll"
      >
        <template #content>
          <div class="item2" v-for="item in data" :key="item">{{ item }}</div>
        </template>
        <template #bottom_info>
          <div style="text-align: center">这回真的到底了</div>
        </template>
      </BasiScrollcLIst>
    </div>
  </div>
</template>

<script setup lang="ts">
import { debounce } from '@/utils'

const data = ref(10)
const scrollRef = ref<any>()

const touch = debounce(() => {
  console.log('触底了')
  if (data.value < 30) {
    data.value = data.value + 10
  }
}, 1000)

function backTop() {
  ;(scrollRef.value.scrollBox as HTMLDivElement)?.scrollTo({
    top: 0,
    left: 0,
    behavior: 'smooth'
  })
}

function scrolling(params) {
  console.log(params)
  // 这里可以做些事
}
</script>

<style lang="less" scoped>
.page {
  width: 1200px;
  margin: auto;
  background-color: rgba(0, 0, 0, 0.1);
  padding-top: 300px;
}
.scroll_container {
  width: 300px;
  height: 300px;
  margin: 200px auto;

  .item {
    width: 100%;
    height: 48px;
    background: rgba(0, 0, 0, 0.2);
  }

  .split {
    width: 100%;
    height: 1px;
    background-color: black;
    margin: 48px 0;
  }

  .x_scroll {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;

    .item2 {
      width: 40px;
      height: 250px;
      background-color: aqua;
      flex-shrink: 0;

      &:not(:last-child) {
        margin-right: 16px;
      }
    }
  }
}
</style>
